<template>
	<div id="home" class="scroll" v-if="home_list.category">
		<NavConter></NavConter>
		<div class="top">
			<!-- 顶部搜索 -->
			<div class="sousuo">
				<div class="logo">
					<img src="../../assets/logo.png" alt="">
				</div>
				<div class="input">
					<span class="iconfont icon-31sousuo"></span>
					<input type="text" placeholder="搜索商品" @click="$router.push('/home/goods_search')">
				</div>
				<div class="icon">
					<span class="iconfont icon-xiaoxi"></span>
				</div>
			</div>

			<!-- 顶部导航栏 -->
			<div class="nav">
				<div class="ul_nav">
					<van-tabs v-model="active" title-active-color="#f00" @click="onClick" title-class="on">
						<van-tab v-for="(item,index) in home_list.category" :key="index" :title="item.cate_name" id="on"
							title-class="on">
							<!-- 内容 -->
							<!-- <PageCom v-show="active == index" :title="item.cate_name"></PageCom> -->
							<!-- 内容 -->
						</van-tab>
					</van-tabs>
				</div>
				<div class="assort">
					<span class="iconfont icon-fenlei"></span>
					<span>分类</span>
				</div>
			</div>
		</div>


		<!-- 内容组件 -->
		<homecontent v-if="active == 0"></homecontent>
		<PageCom v-else v-for="(item,index) in home_list.category" :key="index" v-show="active == index"
			:title="item.store_category_id">
		</PageCom>
		<!-- 内容组件 -->
	</div>

	<SkeletonHome v-else></SkeletonHome>
</template>

<script>
	import {
		Toast
	} from 'vant';
	// <!-- 导入api文件 -->
	import {
		GetIts
	} from "@/api/home"
	import PageCom from '@/components/home/PageCom.vue'
	import homecontent from '@/components/home/homecontent.vue'
	import NavConter from '@/components/NavConter.vue'
	// 骨架屏
	import SkeletonHome from '@/components/Skeleton/home.vue'
	export default {
		name: "home",
		components: {
			PageCom,
			homecontent,
			NavConter,
			SkeletonHome
		},
		data() {
			return {
				active: 0,
				current: 0,
				home_list: [],
				// 首页导航信息
				cat_home: {
					cate_name: "首页",
					pid: 0,
					store_category_id: 0
				}
			}
		},
		created() {
			GetIts().then(res => {
				this.home_list = res.data.data
				this.home_list.category.unshift(this.cat_home)
			})
		},
		methods: {

			onClick(name, title) {
				// 文字
				// Toast(title);
				// 下标
				// Toast(name);
				this.current = name
			}
		}
	}
</script>

<style lang="scss" scoped>
	$width:(100vw / 375);

	#home {
		width: 100vw;
		min-height: 100vh;
		box-sizing: border-box;
		font-size: 16 * $width;
		background-color: #f1f1f1;

		.top {
			background-color: #fff;
			padding-bottom: 6 * $width;

			// 顶部搜索
			.sousuo {
				width: 100%;
				height: 44 * $width;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10 * $width 15 * $width 0 15 * $width;

				.logo {
					img {
						width: 22 * $width;
					}
				}

				.input {
					width: 270 * $width;
					height: 32 * $width;
					position: relative;

					input {
						width: 100%;
						height: 100%;
						border-radius: 16 * $width;
						border: none;
						background-color: #ededed;
						padding-left: 33 * $width;
					}

					span {
						position: absolute;
						top: 5 * $width;
						left: 13 * $width;
						font-size: 16 * $width;
					}
				}

				.icon {
					span {
						font-size: 22 * $width;
					}
				}
			}

			// 顶部导航栏
			.nav {
				padding-top: 12 * $width;
				display: flex;
				align-items: flex-start;

				.ul_nav {
					width: 310 * $width;
					padding-left: 15 * $width;
					height: 50 * $width;
				}

			}



			.assort {
				display: flex;
				align-items: center;
				border-left: 1 * $width solid #cecece;

				margin-top: 7 * $width;

				.icon-fenlei {
					font-size: 20 * $width;
					margin: 0 3 * $width;
				}

				span {
					font-size: 15 * $width;
				}
			}
		}
	}
</style>
